import time

import allure
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from common.basepage import BasePage


class OverviewPage(BasePage):
    """概览页面"""
    """快捷入口-页面元素"""
    #  _locator = (By.XPATH, '')
    # 快速开单入口
    quickOrder_locator = (By.XPATH, '//*[@class="quickEnter_wrap"]/div[1]')
    # 收银台页面元素
    quickOrder_msg_locator = (By.XPATH, '//span[text()="收银台"]')
    # 新增预约入口
    newBooking_locator = (By.XPATH, '//*[@class="quickEnter_wrap"]/div[2]')
    # 新增预约页面元素
    newBooking_msg_locator = (By.XPATH, '//span[@class="el-dialog__title" and text()="新增预约"]')
    newBooking_cancel_locator = (By.XPATH, '//*[@aria-label="新增预约"]/div[3]/span/button[1]')
    # 新增会员入口
    newMembers_locator = (By.XPATH, '//*[@class="quickEnter_wrap"]/div[3]')
    # 新增会员页面元素
    newMembers_msg_locator = (By.XPATH, '//span[text()="新增会员"]')
    # 新增潜客入口
    newPotentialCustomer_locator = (By.XPATH, '//*[@class="quickEnter_wrap"]/div[4]')
    # 新增潜客页面元素
    newPotentialCustomer_msg_locator = (By.XPATH, '//span[@class="el-dialog__title" and text()="新增潜客"]')
    newPotentialCustomer_cancel_locator = (By.XPATH, '//*[@aria-label="新增潜客"]/div[3]/span/button[1]')
    """待办事项-页面元素"""
    # 预约单-待付款
    listPaying_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[1]')
    listPaying_total_locator = (By.XPATH, '//span[@class="el-pagination__total"]')
    listPaying_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[1]/p[1]')

    # 预约单-待服务
    listServer_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[2]')
    listServer_total_locator = (By.XPATH, '//span[@class="el-pagination__total"]')
    listServer_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[2]/p[1]')

    # 预约单-待分配
    listAllot_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[3]')
    listAllot_total_locator = (By.XPATH, '//span[@class="el-pagination__total"]')
    listAllot_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[3]/p[1]')

    # 开单订单-待付款
    orderPaying_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[4]')
    orderPaying_total_locator = (By.XPATH, '//span[@class="el-pagination__total"]')
    orderPaying_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[4]/p[1]')

    # 潜客跟进-待跟进
    potentialCustomer_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[5]')
    potentialCustomer_msg_locator = (By.XPATH, '//li[text()="潜客列表"]')
    potentialCustomer_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[5]/p[1]')

    # 在线订单-待发货
    shipments_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[6]')
    shipments_total_locator = (By.XPATH, '//span[@class="el-pagination__total"]')
    shipments_count_locator = (By.XPATH, '//*[@class="todo_wrap"]/div[6]/p[1]')

    """最新功能-页面元素"""
    # 最新功能-更多
    latestFeatures_more_locator = (By.CSS_SELECTOR, 'div[class*="latest"]>div>span')
    # 首页最新功能，展示5个
    latestFeatures_items_locator = (By.XPATH, '//*[@id="overview"]/div[2]/div[2]/div[3]/div[2]/p')
    # 首页最新功能第一行的标题
    latestFeature_title_locator = (By.CSS_SELECTOR, 'div[class*="latest"]  div.notice_wrap :first-child span')
    # 详情页面标题
    latestFeature_detailTitle_locator = (By.CSS_SELECTOR, 'div.title-center>h2')
    # 全部信息页面 最新功能标签
    latestFeatures_label_locator = (By.CSS_SELECTOR, 'div[role="tablist"]>:nth-child(2)>span')


    """系统公告-页面元素"""
    # 系统公告-更多
    systemNotice_more_locator = (By.XPATH, '//*[@id="overview"]/div[2]/div[2]/div[4]/div[1]/span')
    # 首页系统公告，展示4个
    systemNotice_items_locator = (By.XPATH, '//*[@id="overview"]/div[2]/div[2]/div[4]/div[2]/p')
    # 第一行首页最新功能的标题
    systemNotice_title_locator = (By.CSS_SELECTOR, 'div.overview_right>div:last-child  p.notice_item:first-child>span')
    # 详情页面标题
    systemNotice_detailTitle_locator = (By.CSS_SELECTOR, 'div.title-center>h2')
    # 全部信息页面 最新功能标签
    systemNotice_label_locator = (By.CSS_SELECTOR, 'div[role="tablist"]>:nth-child(3)>span')

    """快捷入口-功能"""
    allure.step("点击快速开单，打开收银台页面")
    def quickOrder(self):
        self.visible_only_wait(self.quickOrder_locator).click()

    allure.step("获取收银台页面信息")
    def get_quickOrder_msg(self):
        return self.visible_only_wait(self.quickOrder_msg_locator)

    allure.step("点击新增预约，打开新增预约页面")
    def newBooking(self):
        self.visible_only_wait(self.newBooking_locator).click()

    allure.step("获取新增预约页面信息")
    def get_newBooking_msg(self):
        return self.visible_only_wait(self.newBooking_msg_locator)


    allure.step("点击新增会员，打开新增会员页面")
    def newMembers(self):
        self.visible_only_wait(self.newMembers_locator).click()

    allure.step("获取新增会员页面信息")
    def get_newMembers_msg(self):
        return self.visible_only_wait(self.newMembers_msg_locator)

    allure.step("点击新增潜客，打开新增潜客页面")
    def newPotentialCustomer(self):
        self.visible_only_wait(self.newPotentialCustomer_locator).click()

    allure.step("获取新增潜客页面信息")
    def get_newPotentialCustomer_msg(self):
        return self.visible_only_wait(self.newPotentialCustomer_msg_locator)

    """待办事项-功能"""

    """预约单-待付款"""
    allure.step("获取概览页面预约单-待付款的任务数")
    def get_listPaying_count(self):
        listPaying_count = self.visible_only_wait(self.listPaying_count_locator).text
        return listPaying_count

    allure.step("点击预约单-待付款，打开预约列表页面")
    def click_listPaying(self):
        self.visible_only_wait(self.listPaying_locator).click()

    allure.step("获取预约列表页面-待付款的任务数")
    def get_listPaying_total(self):
        return self.visible_only_wait(self.listPaying_total_locator)

    """预约单-待服务"""
    allure.step("获取概览页面预约单-待服务的任务数")
    def get_listServer_count(self):
        listServer_count = self.visible_only_wait(self.listServer_count_locator).text
        return listServer_count

    allure.step("点击预约单-待服务，打开预约列表页面")
    def click_listServer(self):
        self.visible_only_wait(self.listServer_locator).click()

    allure.step("获取预约列表页面-待服务的任务数")
    def get_listServer_total(self):
        time.sleep(1)
        return self.visible_only_wait(self.listServer_total_locator)

    """预约单-待分配"""
    allure.step("获取概览页面预约单-待分配的任务数")
    def get_listAllot_count(self):
        listAllot_count = self.visible_only_wait(self.listAllot_count_locator).text
        return listAllot_count

    allure.step("点击预约单-待分配，打开预约列表页面")
    def click_listAllot(self):
        self.visible_only_wait(self.listAllot_locator).click()

    allure.step("获取预约列表页面-待分配的任务数")
    def get_listAllot_total(self):
        time.sleep(1)
        return self.visible_only_wait(self.listAllot_total_locator)

    """开单订单-待付款"""
    allure.step("获取概览页面开单订单-待付款的任务数")
    def get_orderPaying_count(self):
        orderPaying_count = self.visible_only_wait(self.orderPaying_count_locator).text
        return orderPaying_count

    allure.step("点击开单订单-待付款，打开订单列表页面")
    def click_orderPaying(self):
        self.visible_only_wait(self.orderPaying_locator).click()

    allure.step("获取订单列表页面-待付款的任务数")
    def get_orderPaying_total(self):
        time.sleep(1)
        return self.visible_only_wait(self.orderPaying_total_locator)

    """潜客跟进-待跟进"""

    allure.step("点击潜客跟进-待跟进，打开潜客列表页面")
    def click_potentialCustomer(self):
        self.visible_only_wait(self.potentialCustomer_locator).click()

    allure.step("打开潜客列表页面,获取潜客列表标题")
    def get_potentialCustomer_msg(self):
        return self.visible_only_wait(self.potentialCustomer_msg_locator)

    """在线订单-待发货"""

    allure.step("获取概览页面在线订单-待发货的任务数")
    def get_shipments_count(self):
        shipments_count = self.visible_only_wait(self.shipments_count_locator).text
        return shipments_count

    allure.step("点击开单订单-待付款，打开订单列表页面")
    def click_shipments(self):
        self.visible_only_wait(self.shipments_locator).click()

    allure.step("获取订单列表页面-待付款的任务数")
    def get_shipments_total(self):
        return self.visible_only_wait(self.shipments_total_locator)

    """最新功能-功能"""
    allure.step("获取首页最新功能第一行的标题")
    def get_latestFeature_title(self):
        return self.visible_only_wait(self.latestFeature_title_locator)

    allure.step("点击首页最新功能第一行的标题")
    def click_latestFeature_title(self):
        self.visible_only_wait(self.latestFeature_title_locator).click()

    allure.step("获取最新功能详情页面的标题")
    def get_latestFeature_detailTitle(self):
        time.sleep(1)
        return self.visible_only_wait(self.latestFeature_detailTitle_locator)

    allure.step("点击首页最新功能的更多")
    def click_latestFeatures_more(self):
        self.visible_only_wait(self.latestFeatures_more_locator).click()

    allure.step("获取全部信息页面 最新功能标签")
    def get_latestFeatures_label(self):
        return self.visible_only_wait(self.latestFeatures_label_locator)


    """系统公告-功能"""
    allure.step("获取首页系统公告第一行的标题")
    def get_systemNotice_title(self):
        return self.visible_only_wait(self.systemNotice_title_locator)

    allure.step("点击首页系统公告第一行的标题")
    def click_systemNotice_title(self):
        self.visible_only_wait(self.systemNotice_title_locator).click()

    allure.step("获取系统公告详情页面的标题")
    def get_systemNotice_detailTitle(self):
        time.sleep(1)
        return self.visible_only_wait(self.systemNotice_detailTitle_locator)

    allure.step("点击系统公告的更多")
    def click_systemNotice_more(self):
        # self.visible_only_wait(self.systemNotice_more_locator).click()
        element = self.visible_only_wait(self.systemNotice_more_locator)
        self.JS_click(element)


    allure.step("获取系统公告页面 系统公告标签")
    def get_systemNotice_label(self):
        return self.visible_only_wait(self.systemNotice_label_locator)